package com.augurit.gzcgwsp.jzfqwczzpfsn.service.impl;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import jxl.format.Alignment;
import jxl.format.VerticalAlignment;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

import com.augurit.common.system.web.auth.form.LoginUserForm;
import com.augurit.common.util.HqlUtils;
import com.augurit.common.util.PageUtils;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.commonex.util.lang.DateUtilsEX;
import com.augurit.gzcgwsp.excelimportexport.util.ExcelUtil;
import com.augurit.gzcgwsp.excelimportexport.util.FileUtil;
import com.augurit.gzcgwsp.excelimportexport.util.GetFileName;
import com.augurit.gzcgwsp.jzfqwczz.common.service.IYwYnJzfqwczzCsService;
import com.augurit.gzcgwsp.jzfqwczz.common.service.IYwYnJzfqwczzXckcService;
import com.augurit.gzcgwsp.jzfqwczz.common.web.form.YwYnJzfqwczzCsForm;
import com.augurit.gzcgwsp.jzfqwczz.common.web.form.YwYnJzfqwczzXckcForm;
import com.augurit.gzcgwsp.jzfqwczzpfsn.convert.YwYnJzfqwczzPfsnConvert;
import com.augurit.gzcgwsp.jzfqwczzpfsn.dao.YwYnJzfqwczzPfsnDao;
import com.augurit.gzcgwsp.jzfqwczzpfsn.entity.YwYnJzfqwczzPfsn;
import com.augurit.gzcgwsp.jzfqwczzpfsn.service.IYwYnJzfqwczzPfsnyqQxService;
import com.augurit.gzcgwsp.jzfqwczzpfsn.web.form.YwYnJzfqwczzPfsnForm;
import com.augurit.gzcgwsp.sendNotice.service.IExchangeStateService;
import com.augurit.gzcgwsp.sendNotice.service.IYwMtbjlshInfoService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceForWbService;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceInfoService;
import com.augurit.gzcgwsp.wfex.common.service.IWfServiceEX;
import com.augurit.gzcgwsp.ywcmn.service.IYwComQyxxService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComQyxxTwoService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjclService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjcllistService;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxTwoForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComSjclForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComSjcllistForm;
import com.augurit.wf.app.doccode.service.IOaDocCodeService;
import com.augurit.wf.bi.web.form.WfBusInstanceTaskForm;
import com.augurit.wf.common.service.impl.WfBusClientServiceImpl;

@Service
@Transactional
public class YwYnJzfqwczzPfsnyqQxServiceImpl extends WfBusClientServiceImpl<YwYnJzfqwczzPfsnForm> implements IYwYnJzfqwczzPfsnyqQxService {
	 private static final Logger log = Logger.getLogger(YwYnJzfqwczzPfsnyqQxServiceImpl.class);
	@Autowired
	private YwYnJzfqwczzPfsnDao ywYnJzfqwczzPfsnDao;
    @Autowired
    private IYwComQyxxService ywComQyxxService;
    @Autowired
    private IYwComSjclService sjclService;
    @Autowired
    private IYwComSjcllistService ywComSjcllistService;
    @Autowired
    private IYwComSjclService ywComSjclService;
    @Autowired
    private IYwYnJzfqwczzXckcService ywYnJzfqwczzXckcService;    
    @Autowired
    private IYwYnJzfqwczzCsService ywYnJzfqwczzCsService;
    @Autowired
    private IYwComQyxxTwoService ywComQyxxTwoService;
    @Autowired
    private IYwMtbjlshInfoService ywMtbjlshInfoService;
    @Autowired
	private IYwWebserviceInfoService ywWebserviceInfoService;
    @Autowired
    private IYwWebserviceForWbService ywWebserviceForWbService;
    @Autowired
    private IExchangeStateService exchangeStateService;
    @Autowired
    private IWfServiceEX wfServiceEX;
    
	/**
	 * ��������ȡForm����
	 */
	@Transactional(readOnly = true)
	public YwYnJzfqwczzPfsnForm get(Long id) {
		YwYnJzfqwczzPfsn entity = ywYnJzfqwczzPfsnDao.get(id);
		YwYnJzfqwczzPfsnForm form=YwYnJzfqwczzPfsnConvert.convertVoToForm(entity);
		YwComSjcllistForm sjclListForm=new YwComSjcllistForm();
		//获取企业信息表信息
		if(form.getQyid() != null){
			YwComQyxxForm qyxxform = ywComQyxxService.get(form.getQyid());
			YwYnJzfqwczzPfsnConvert.convertQyxxFormToForm(qyxxform, form);
		}
		//获取现场勘察表信息
        if(form.getXckcid() != null){
        	YwYnJzfqwczzXckcForm ywYnJzfqwczzXckcForm = ywYnJzfqwczzXckcService.get(form.getXckcid());
        	YwYnJzfqwczzPfsnConvert.convertXckcFormToForm(ywYnJzfqwczzXckcForm, form);
        }        
        //获取初审表信息
        if(form.getCsid() != null){
        	YwYnJzfqwczzCsForm ywYnJzfqwczzCsForm = ywYnJzfqwczzCsService.get(form.getCsid());
        	YwYnJzfqwczzPfsnConvert.convertCsFormToForm(ywYnJzfqwczzCsForm, form);
        }
        
        sjclListForm.setAjid(id);
        sjclListForm.setTplcode("jzfqwczzpfqx_yq");
        List<YwComSjcllistForm> sjclList = ywComSjcllistService.getList(sjclListForm);
        YwComSjclForm fkForm = new YwComSjclForm();
        fkForm.setFkid(form.getQyid());
        fkForm.setAjid(id);
        fkForm.setTplcode("jzfqwczzpfqx_yq");
        List<YwComSjclForm> sjclTpl = ywComSjclService.getList(fkForm);
        for (YwComSjcllistForm listForm : sjclList) {
            boolean hasExists = false;
            for (YwComSjclForm tplForm : sjclTpl) {
                if (tplForm.getTplid() != null && listForm.getId().longValue() == tplForm.getTplid().longValue()) {
                    if (StringUtils.isNotBlank(tplForm.getFilepath())) {
                        listForm.setState("1");
                        listForm.setHasfile("1");
                        listForm.setFilename(tplForm.getFilename());
                        listForm.setFilepath(tplForm.getFilepath());
                        listForm.setFiletype(tplForm.getFiletype());
                    } else {
                        listForm.setState("0");
                        listForm.setHasfile("0");
                    }
                    if (tplForm.getYjs() != null) {
                        listForm.setYjs(Long.valueOf(tplForm.getYjs()));
                    }
                    if (tplForm.getFyjs() != null) {
                        listForm.setFyjs(Long.valueOf(tplForm.getFyjs()));
                    }
                    listForm.setClid(tplForm.getId());
                    if ("1".equals(listForm.getSfdz())) {//是否电子材料
                        listForm.setDisabled("1");
                    } else {
                        listForm.setDisabled("0");
                        if (tplForm.getSfdz() == null) {
                            listForm.setSfdz("0");
                        } else {
                            listForm.setSfdz(tplForm.getSfdz());
                        }
                    }
                    hasExists = true;
                }
            }
            if (!hasExists) {
                listForm.setState("0");
                listForm.setHasfile("0");
                if ("1".equals(listForm.getSfdz())) {
                    listForm.setDisabled("1");
                } else {
                    listForm.setDisabled("0");
                }
            }
        }
        
        form.setAcceptNo2(form.getAcceptNo());
        form.setAcceptNo3(form.getAcceptNo());
        form.setCbyw2(form.getCbyw());
        form.setCbyw3(form.getCbyw());
        form.setCbyw4(form.getCbyw());
        form.setCbyw5(form.getCbyw());
        form.setSqdw3(form.getSqdw());
        form.setSjr2(form.getSjr());
        form.setSqdw2(form.getSqdw());
        
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
        
        
        form.setLxr2(form.getJsdwLxr());
        form.setYwlxr(form.getLxr2());
        if(form.getSqDate() != null){
        	form.setSqrq2(format.format(form.getSqDate()));
        	form.setSqrq3(format.format(form.getSqDate()));
        	form.setSqrq4(format.format(form.getSqDate()));
        	form.setSqrq5(format.format(form.getSqDate()));
        }

    	form.setCurDate2(format.format(new Date()));
        form.setCurDate3(format.format(new Date()));
        
        if(form.getSqDate() != null){
            form.setLarq3(format.format(form.getSqDate()));
        	form.setLarq4(format.format(form.getSqDate()));
        }else{
        	form.setLarq3(format.format(new Date()));
        	form.setLarq4(format.format(new Date()));
        }  
      //打印的备注
        if(StringUtils.isBlank(form.getBz())){
        	String bz="";
			if(StringUtils.isNotBlank(form.getSgdwjdy())){
				bz+="施工单位现场监督员："+form.getSgdwjdy();
			}
			if(StringUtils.isNotBlank(form.getSgdwjdydh())){
				bz+=",电话："+form.getSgdwjdydh()+"。";
			}
			if(StringUtils.isNotBlank(form.getYsdwjdy())){
				bz+="运输单位现场监督员："+form.getYsdwjdy();
			}
			if(StringUtils.isNotBlank(form.getYsdwjdydh())){
				bz+=",电话："+form.getYsdwjdydh()+"。";
			}
			form.setBz(bz);
		}
		return form;
        //return YwYnJzfqwczzPfsnConvert.convertVoToForm(entity);
	}
	
	/**
	 * ɾ��Form�����б�
	 */
	public void delete(Long... ids) {
		ywYnJzfqwczzPfsnDao.delete(ids);
	}

	/**
	 * �����������޸ĵ�Form�����б�
	 */
	public void save(YwYnJzfqwczzPfsnForm... forms) {
		if(forms != null)
			for(YwYnJzfqwczzPfsnForm form : forms)
				this.save(form);
	}
	
	/**
	 * �����������޸ĵ�Form����
	 */
	public void save(YwYnJzfqwczzPfsnForm form){
		
		if(form != null){
			YwYnJzfqwczzPfsn entity = null;
			//׼��VO����
			if(form != null && form.getId() != null){
				entity = ywYnJzfqwczzPfsnDao.get(form.getId());
				if (StringUtils.isBlank(entity.getAcceptNo()) || form.getAcceptNo().indexOf("XXXX") > 0) 
				    form.setAcceptNo(null);
			}else{
				entity = new YwYnJzfqwczzPfsn();
                form.setAcceptNo(null);
			}
			//保存企业信息
	        YwComQyxxForm qyxxForm = new YwComQyxxForm();
	        if(form.getQyid() == null){
	        	if(StringUtils.isNotBlank(form.getSqdw())){
	            	YwComQyxxForm ywComQyxxForm = ywComQyxxService.getFormBySqdw(form.getSqdw(), "jzfqwczzpfqx_yq");
	            	if(ywComQyxxForm != null){
	            		qyxxForm = ywComQyxxForm;
	            	}
	            }
	        }
	        YwYnJzfqwczzPfsnConvert.convertFormToQyxxForm(form, qyxxForm);
	        qyxxForm.setTemplateCode("jzfqwczzpfqx_yq");
	        ywComQyxxService.update(qyxxForm);
	        form.setQyid(qyxxForm.getId());
	        
	        //保存施工单位信息到 企业信息表2
			YwComQyxxTwoForm ywComQyxxTwoForm = new YwComQyxxTwoForm();
	        YwYnJzfqwczzPfsnConvert.convertFormToQyxxTwoForm(form, ywComQyxxTwoForm);
	        ywComQyxxTwoForm.setTemplateCodeTwo("jzfqwczzpfqx_yq");
	        ywComQyxxTwoService.update(ywComQyxxTwoForm);
	        form.setQybhTwo((ywComQyxxTwoForm.getId()).toString());
	        
	        //保存现场勘察表
	        YwYnJzfqwczzXckcForm ywYnJzfqwczzXckcForm = new YwYnJzfqwczzXckcForm();
	        YwYnJzfqwczzPfsnConvert.convertFormToXckcForm(form, ywYnJzfqwczzXckcForm);
	        ywYnJzfqwczzXckcForm.setTplcode("jzfqwczzpfqx_yq");
	        ywYnJzfqwczzXckcService.update(ywYnJzfqwczzXckcForm);
	        form.setXckcid(ywYnJzfqwczzXckcForm.getId());
	        
	        //保存初审表
	        YwYnJzfqwczzCsForm ywYnJzfqwczzCsForm = new YwYnJzfqwczzCsForm();
	        YwYnJzfqwczzPfsnConvert.convertFormToCsForm(form, ywYnJzfqwczzCsForm);
	        ywYnJzfqwczzCsForm.setTplcode("jzfqwczzpfqx_yq");
	        ywYnJzfqwczzCsService.update(ywYnJzfqwczzCsForm);
	        form.setCsid(ywYnJzfqwczzCsForm.getId());
	        
	        boolean isNewForm = false;
            if (StringUtils.isBlank(form.getAcceptNo())) {
            	//生成政务中心统一查询编号 开始
    			Map<String,String> serialNoAndPasswordMap = null;
//            	if("Y".equals(form.getSendNotice())){//网办，1
//            		serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("1");
//            	}else{//大厅，0
//            		serialNoAndPasswordMap = ywMtbjlshInfoService.getSerialNoAndPassword("0");
//            	}
    			String area=form.getArea();
    			area=area.substring(0,2);
    			if("Y".equals(form.getSendNotice())){//网办，1
    				serialNoAndPasswordMap = ywMtbjlshInfoService.getQuSerialNoAndPassword("1",area);//大厅
    	        }else{//大厅，0
            		serialNoAndPasswordMap = ywMtbjlshInfoService.getQuSerialNoAndPassword("0",area);//大厅
    	        }
            	String serialNo = serialNoAndPasswordMap.get("serialNo");
            	String password = serialNoAndPasswordMap.get("password");
    			form.setSerialNo(serialNo);
    			form.setPassword(password);
    			form.setAcceptNo(serialNo);
        		//生成政务中心统一查询编号 结束
                isNewForm = true;            
            }
            
            String acceptNo="";
            if(entity!=null && StringUtils.isNotBlank(entity.getAcceptNo())){//有时会出现acceptno2和acceptno不一致
            	 acceptNo=entity.getAcceptNo();
            	 form.setAcceptNo(acceptNo);
            }
            form.setBranch("jzfqwczzpfqx_yq");
            YwYnJzfqwczzPfsnConvert.convertFormToVo(form, entity);
          	//如果没有申请减免分期付款
			if(StringUtils.isNotBlank(entity.getNeedSqjmfqfk()) && "2".endsWith(entity.getNeedSqjmfqfk())){
				entity.setJmfqly(null);
			}
			//
			System.out.println("entity.getSerialNo() = "+entity.getSerialNo());
			ywYnJzfqwczzPfsnDao.save(entity);
			
			//����ID����ֵ
			form.setId(entity.getId());
			if (isNewForm) {
                sjclService.updateByNewForm(form.getId());
            }
		}
	}

	/**
	 * ���Form����Ĳ�ѯ��������ҳ��ѯ
	 */
	@Transactional(readOnly = true)
	public Page<YwYnJzfqwczzPfsnForm> search(Page<YwYnJzfqwczzPfsnForm> page, YwYnJzfqwczzPfsnForm form) {
		// �����µķ�ҳ����
		Page pg = PageUtils.newPageInstance(page);
		
		// ��ѯ��估����
		StringBuffer hql = new StringBuffer("from YwYnJzfqwczzPfsn ps where 1=1");
		List values = new ArrayList();
		
		// ��ѯ����
		if(form != null){
			
		}
		
		//����
		hql.append(HqlUtils.buildOrderBy(page, "ps"));
		
		// ִ�з�ҳ��ѯ����
		ywYnJzfqwczzPfsnDao.findPage(pg, hql.toString(), values);
		
		// ת��ΪForm�����б?��ֵ��ԭ��ҳ������
		List<YwYnJzfqwczzPfsnForm> list = YwYnJzfqwczzPfsnConvert.convertVoListToFormList(pg.getResult());
		PageUtils.copy(pg, list, page);
		return page;
	}
	
	/**
	 * ��ݹ��������б�����ҳ��ѯ
	 */
	@Transactional(readOnly = true)
	public Page<YwYnJzfqwczzPfsnForm> search(Page<YwYnJzfqwczzPfsnForm> page, List<PropertyFilter> filters) {
		// �����µķ�ҳ����
		Page<YwYnJzfqwczzPfsn> pg = PageUtils.newPageInstance(page);
		
		// ������������ҳ���Ҷ���
		ywYnJzfqwczzPfsnDao.findPage(pg, filters);
		
		// ת��ΪForm�����б?��ֵ��ԭ��ҳ������
		List<YwYnJzfqwczzPfsnForm> list = YwYnJzfqwczzPfsnConvert.convertVoListToFormList(pg.getResult());
		PageUtils.copy(pg, list, page);
		return page;
	}
	
	public void changeYslState(Long id,Long state,String yslThyy) {
    	StringBuffer sql = new StringBuffer();
    	sql.append("update YwYnJzfqwczzPfsn t set t.ysl="+state);
    	if(StringUtils.isNotBlank(yslThyy)){
    		sql.append(" ,t.yslThyy='"+yslThyy+"'");
    	}
    	sql.append(" where t.id="+id);
    	ywYnJzfqwczzPfsnDao.getSession().createQuery(sql.toString()).executeUpdate();
    	System.out.println("排放区县-延期 收件");
    }
	
	public List<YwYnJzfqwczzPfsn> getByAcceptNo(String acceptNo)
	{
		String sql = "from YwYnJzfqwczzPfsn t where t.acceptNo='" + acceptNo + "'";
        List<YwYnJzfqwczzPfsn> entityList = ywYnJzfqwczzPfsnDao.find(sql);
        return entityList;
	}

	/*
	 * (non-Javadoc)
	 * @see com.augurit.gzcgwsp.jzfqwczzpfsn.service.IYwYnJzfqwczzPfsnService#printZs(com.augurit.gzcgwsp.jzfqwczzpfsn.web.form.YwYnJzfqwczzPfsnForm, java.lang.String)
	 */
	@Override
	public String printZs(YwYnJzfqwczzPfsnForm form, String context) {
		   String inpath=context+"/Templates/ynpf/ynpfczz.xls";//模版路径
		   inpath=inpath.replace("/", File.separator);
	        String tempOutPath="Templates/ynpf/outfile";
	        tempOutPath=this.buildPath(tempOutPath, "xls");
	        String outfilepath=context+"/"+tempOutPath;
	        outfilepath=outfilepath.replace("/", File.separator);
	        String outdir=outfilepath.substring(0,outfilepath.lastIndexOf(File.separator));
	        File file=new File(outdir);
	        if(!file.exists()){
	            file.mkdirs();
	        }
	        writerDataExcel(inpath,outfilepath,form);
	     	String dir=outfilepath.substring(0,outfilepath.lastIndexOf(File.separator));
			String filename=outfilepath.substring(outfilepath.lastIndexOf(File.separator)+1,outfilepath.length());
			try {//删除其他文件
				FileUtil.delDir(dir,filename);
			} catch (IOException e) {
				e.printStackTrace();
			}
	        return tempOutPath;
		
	}
    /**
     * 生成后面的文件路径加上年月
     * @param realpath 定义的目录
     * @param fileNamesuffix 文件后缀名
     * @return
     */
    private String buildPath(String realpath,String fileNamesuffix){
        String fileName = GetFileName.getFileName(fileNamesuffix);
        String dateDir = GetFileName.getDirector();
        return realpath+"/"+dateDir+"/"+fileName;
        
    }
    /**
     * 复制模版写入数据
     * @param inpath
     * @param outfilepath
     * @param form
     */
    private void writerDataExcel(String inpath, String outfilepath,
    		YwYnJzfqwczzPfsnForm form) {
        WritableWorkbook wwb;
        try {
            wwb = ExcelUtil.createWorkbookByOld(inpath, outfilepath);
            WritableSheet wsOne = ExcelUtil.getWritableSheetByIndex(wwb, 0);
            copyZsData(wsOne,form);
            wsOne.setProtected(true);
            wwb.write();
            wwb.close();
        } catch (Exception e) {
            log.error("写文件错误"+e);
        } 
    }
    
    
    /**
     * 写数据
     * @param wsOne
     * @param form
     */
    private void copyZsData(WritableSheet wsOne, YwYnJzfqwczzPfsnForm form) {
       
        try {
            WritableCellFormat wcf=ExcelUtil.createCellFormat("宋体", 18, Alignment.LEFT, VerticalAlignment.CENTRE,false);
            WritableCellFormat wcf1=ExcelUtil.createCellFormat("宋体", 20, Alignment.LEFT, VerticalAlignment.CENTRE,true);
            WritableCellFormat wcf2=ExcelUtil.createCellFormat("宋体", 20, Alignment.CENTRE, VerticalAlignment.CENTRE,false);
            WritableCellFormat wcf3=ExcelUtil.createCellFormat("宋体", 20, Alignment.RIGHT, VerticalAlignment.CENTRE,false);
            wcf.setLocked(true);
            wcf1.setLocked(true);
            wcf2.setLocked(true);
            wcf3.setLocked(true);
            ExcelUtil.modiStrCell2(wsOne, 3,11, form.getZsno()==null?"":form.getZsno(), wcf);//编号
            ExcelUtil.modiStrCell2(wsOne, 10, 11, form.getZsbh()==null?"":form.getZsbh(), wcf);//编号
            Date fzrq=form.getFzrq();
            if(fzrq!=null){
                String fzrqstr=DateUtilsEX.dateFormate(fzrq, "yyyy年MM月dd日");
                String year=fzrqstr.substring(0,4);
                String month=fzrqstr.substring(5,7);
                String day=fzrqstr.substring(8,10);
                ExcelUtil.modiStrCell2(wsOne,4, 29, year==null?"":year, wcf1);//发证日期年
                ExcelUtil.modiStrCell2(wsOne,8, 29, month==null?"":month, wcf1);//月
                ExcelUtil.modiStrCell2(wsOne,11, 29, day==null?"":day, wcf1);//日
            }
   
            ExcelUtil.modiStrCell2(wsOne,27, 2, form.getSqdw()==null?"":form.getSqdw(), wcf);//建设单位
            ExcelUtil.modiStrCell2(wsOne,27, 4, form.getJsdwLxr()==null?"": form.getJsdwLxr(), wcf);//联系人
            ExcelUtil.modiStrCell2(wsOne,37, 4,form.getJsdwLxrLxdh()==null?"":form.getJsdwLxrLxdh(), wcf);//电话
            ExcelUtil.modiStrCell2(wsOne,27, 6, form.getGcmc()==null?"":form.getGcmc(), wcf);//工程地址
            ExcelUtil.modiStrCell2(wsOne,27, 8, form.getGcdz()==null?"":form.getGcdz(), wcf);//工程地址
            ExcelUtil.modiStrCell2(wsOne,27, 11, form.getPfczl()==null?"":form.getPfczl(), wcf);//排放处置量
            String ysgsKgrq=form.getYsgsKgrq()==null?"":form.getYsgsKgrq();
            String ysgsWgrq=form.getYsgsWgrq()==null?"":form.getYsgsWgrq();
           
            if(ysgsKgrq.length()>10 && ysgsWgrq.length()>10){
	            	 String syear=ysgsKgrq.substring(0,4);
	                 String smonth=ysgsKgrq.substring(5,7);
	                 String sday=ysgsKgrq.substring(8,10);
	                 String eyear=ysgsWgrq.substring(0,4);
	                 String emonth=ysgsWgrq.substring(5,7);
	                 String eday=ysgsWgrq.substring(8,10);
            	   ExcelUtil.modiStrCell2(wsOne, 28, 13, syear==null?"":syear, wcf2);//有效期开始时间年
                   ExcelUtil.modiStrCell2(wsOne, 32, 13, smonth==null?"":smonth,wcf1);//有效期开始时间月
                   ExcelUtil.modiStrCell2(wsOne, 34, 13, sday==null?"":sday, wcf1);//有效期日期日
                   ExcelUtil.modiStrCell2(wsOne, 35, 13, eyear==null?"":eyear, wcf2);//有效期日期结束年
                   ExcelUtil.modiStrCell2(wsOne, 37, 13, emonth==null?"":emonth, wcf2);//有效期日期结束月
                   ExcelUtil.modiStrCell2(wsOne, 40, 13, eday==null?"":eday, wcf3);//有效期日期结束天
            }
         
            ExcelUtil.modiStrCell2(wsOne, 27, 15, form.getBz()==null?"":form.getBz(), wcf1);//备注
            
        } catch (Exception e) {
            e.printStackTrace();
            log.error("写入正式数据出现错误"+e);
        }        
    }
	
	public String wfBusYslTuih(YwYnJzfqwczzPfsnForm form,LoginUserForm loginUser) throws Exception {
    	String  loginUserName = loginUser.getUser().getUserName();
    	WfBusInstanceTaskForm taskForm = new WfBusInstanceTaskForm();
		taskForm.setHandleComments("资料不全，不予受理。");
		//把审批状态数据保存到ywWebserviceInfo ，交换给方欣
		ywWebserviceInfoService.saveYwWebserviceInfo(form.getSarq(), form.getAcceptNo(), form.getCbyw(), form.getYwlxr(), form.getSjr(), form.getSqdw(), 
				form.getBusinessCode(), form.getApprovalNo(), loginUserName, loginUser.getOrg().getOrgName(), "ysl", new Date(), false, "预受理", taskForm);
//		System.out.println("form.getYslThyy() = "+java.net.URLDecoder.decode(form.getYslThyy(),"UTF-8"));
		this.changeYslState(form.getId(), 0L,taskForm.getHandleComments());
		
		//（网办）交换到市民网页
		Map<String,String> map=exchangeStateService.buildMap(loginUser, null, form.getId().toString(), form.getTemplateCode(), false);
		String durationExpression = wfServiceEX.getDurationExpressionByTemplateCode(form.getTemplateCode());
		ywWebserviceForWbService.setValueAndSaveYwWebserviceForWb(loginUserName,form.getTemplateCode(),
				form.getId().toString(),durationExpression,"001",taskForm.getHandleComments(), map);
    	return null;
    }
}
